package com.sc.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sc.springboot.pojo.UserFollow;
import com.sc.springboot.service.IUserFollowService;
import com.sc.springboot.util.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author romeo
 * @since 2025-09-23 09:47:13
 */
@RestController
@RequestMapping("/userFollow")
//关注记录
public class UserFollowController {

    @Autowired
    private IUserFollowService userFollowService;

    //关注和取消关注接口
    @RequestMapping("/add")
    public ResponseMsg add(UserFollow userFollow){
        //查询关注记录并判断是否已关注
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userFollow.getUserId());
        queryWrapper.eq("follow_id",userFollow.getFollowId());
        UserFollow follow = userFollowService.getOne(queryWrapper);
        if (follow != null){
            return ResponseMsg.getInstance(ResponseMsg.FAIL,"已关注");
        }else if (userFollowService.save(userFollow)){
            return ResponseMsg.getInstance(ResponseMsg.SUCCESS,"关注成功");
        }
        return ResponseMsg.getInstance(ResponseMsg.FAIL,"关注失败");
    }



}
